<?php

// TTTTTTTTTTTTTTTTTTTTTTT                  MMMMMMMM               MMMMMMMM                                CCCCCCCCCCCCMMMMMMMM               MMMMMMMM  SSSSSSSSSSSSSSS 
// T:::::::::::::::::::::T                  M:::::::M             M:::::::M                             CCC::::::::::::M:::::::M             M:::::::MSS:::::::::::::::S
// T:::::::::::::::::::::T                  M::::::::M           M::::::::M                           CC:::::::::::::::M::::::::M           M::::::::S:::::SSSSSS::::::S
// T:::::TT:::::::TT:::::T                  M:::::::::M         M:::::::::M                          C:::::CCCCCCCC::::M:::::::::M         M:::::::::S:::::S     SSSSSSS
// TTTTTT  T:::::T  TTTTTppppp   ppppppppp  M::::::::::M       M::::::::::M   eeeeeeeeeeee          C:::::C       CCCCCM::::::::::M       M::::::::::S:::::S            
//         T:::::T       p::::ppp:::::::::p M:::::::::::M     M:::::::::::M ee::::::::::::ee       C:::::C             M:::::::::::M     M:::::::::::S:::::S            
//         T:::::T       p:::::::::::::::::pM:::::::M::::M   M::::M:::::::Me::::::eeeee:::::ee     C:::::C             M:::::::M::::M   M::::M:::::::MS::::SSSS         
//         T:::::T       pp::::::ppppp::::::M::::::M M::::M M::::M M::::::e::::::e     e:::::e     C:::::C             M::::::M M::::M M::::M M::::::M SS::::::SSSSS    
//         T:::::T        p:::::p     p:::::M::::::M  M::::M::::M  M::::::e:::::::eeeee::::::e     C:::::C             M::::::M  M::::M::::M  M::::::M   SSS::::::::SS  
//         T:::::T        p:::::p     p:::::M::::::M   M:::::::M   M::::::e:::::::::::::::::e      C:::::C             M::::::M   M:::::::M   M::::::M      SSSSSS::::S 
//         T:::::T        p:::::p     p:::::M::::::M    M:::::M    M::::::e::::::eeeeeeeeeee       C:::::C             M::::::M    M:::::M    M::::::M           S:::::S
//         T:::::T        p:::::p    p::::::M::::::M     MMMMM     M::::::e:::::::e                 C:::::C       CCCCCM::::::M     MMMMM     M::::::M           S:::::S
//       TT:::::::TT      p:::::ppppp:::::::M::::::M               M::::::e::::::::e                 C:::::CCCCCCCC::::M::::::M               M::::::SSSSSSS     S:::::S
//       T:::::::::T      p::::::::::::::::pM::::::M               M::::::Me::::::::eeeeeeee          CC:::::::::::::::M::::::M               M::::::S::::::SSSSSS:::::S
//       T:::::::::T      p::::::::::::::pp M::::::M               M::::::M ee:::::::::::::e            CCC::::::::::::M::::::M               M::::::S:::::::::::::::SS 
//       TTTTTTTTTTT      p::::::pppppppp   MMMMMMMM               MMMMMMMM   eeeeeeeeeeeeee               CCCCCCCCCCCCMMMMMMMM               MMMMMMMMSSSSSSSSSSSSSSS   
//                        p:::::p                                                                                                                                       
//                        p:::::p                                                                                                                                       
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       p:::::::p                                                                                                                                      
//                       ppppppppp                                                                                                                                      

//  _____      __  __         ____ __  __ ____  
// |_   __ __ |  \/  | ___   / ___|  \/  / ___|     | AUTHOR: Xiaohe
//   | || '_ \| |\/| |/ _ \ | |   | |\/| \___ \     | EMAIL: 496631085@qq.com
//   | || |_) | |  | |  __/ | |___| |  | |___) |    | WECHAT: he4966
//   |_|| .__/|_|  |_|\___|  \____|_|  |_|____/     | DATETIME: 2023/03/22
//      |_|                                         | TpMeCMS

declare(strict_types=1);

namespace ImiApp\ApiServer\Api\Controller\user;

use Imi\Db\Db;
use Imi\Server\Http\Route\Annotation\Action;
use Imi\Server\Http\Route\Annotation\Controller;
use Imi\Server\Http\Route\Annotation\Route;
use Psr\Http\Message\ResponseInterface;
use Imi\Aop\Annotation\Inject;
// use Phpben\Imi\Validate\Annotation\Validate;
use Phpben\Imi\Auth\Annotation\Auth;
use ImiApp\ApiServer\Api\Model\GoodsskuPrice;

use Imi\Cache\CacheManager as Cache;

/**
 * 拍卖👏
 * @Auth(name="token",nologin={"get_coupons_list","get_coupons_data","index4"})
 * @Controller("/user.auction/")
 */
class Auction extends UserBean
{
    protected $noNeedLogin = ['no'];
    protected $noNeedRight = ['*'];



    /**
     * 获取拍卖首页4种商品
     * @param string $status 2=预展示,3=进行中
     * @return void
     * @Action
     */
    public function index4($status = '2')
    {
        if (!$status)
            $status = '2';
        $whereCom['apply_status'] = '2'; //申请状态:1=待审核,2=通过,3=拒绝
        // $type_status = 拍卖类型:1=贝壳竞拍,2=降价拍,3=升价拍,4=暗拍(降价拍),5=暗拍(升价拍)
        $type_status1 = Db::name('auction')->where('type_status', '=', '1')->where('status', '=', $status)->whereEx($whereCom)->orderRaw('end_time asc,id desc')->limit(2)->select()->getArray();
        if ($type_status1) {
            foreach ($type_status1 as &$val) {
                $temp = $this->get_field_arr($val, ['id', 'type_status', 'goods_id']);
                $val = $temp;
                $val['goods'] = $this->GetGoodsShortDataById4($val['goods_id']);
            }
        }
        $list['type_status1'] = $type_status1;


        $type_status2 = Db::name('auction')->where('type_status', '=', '2')->where('status', '=', $status)->whereEx($whereCom)->orderRaw('end_time asc,id desc')->limit(2)->select()->getArray();
        if ($type_status2) {
            foreach ($type_status2 as &$val) {
                $temp = $this->get_field_arr($val, ['id', 'type_status', 'goods_id']);
                $val = $temp;
                $val['goods'] = $this->GetGoodsShortDataById4($val['goods_id']);
            }
        }
        $list['type_status2'] = $type_status2;


        $type_status3 = Db::name('auction')->where('type_status', '=', '3')->where('status', '=', $status)->whereEx($whereCom)->orderRaw('end_time asc,id desc')->limit(2)->select()->getArray();
        if ($type_status3) {
            foreach ($type_status3 as &$val) {
                $temp = $this->get_field_arr($val, ['id', 'type_status', 'goods_id']);
                $val = $temp;
                $val['goods'] = $this->GetGoodsShortDataById4($val['goods_id']);
            }
        }
        $list['type_status3'] = $type_status3;


        $type_status4 = Db::name('auction')->where('type_status', '=', '4')->where('status', '=', $status)->whereEx($whereCom)->orderRaw('end_time asc,id desc')->limit(1)->select()->getArray();
        if ($type_status4) {
            foreach ($type_status4 as &$val) {
                $temp = $this->get_field_arr($val, ['id', 'type_status', 'goods_id']);
                $val = $temp;
                $val['goods'] = $this->GetGoodsShortDataById4($val['goods_id']);
            }
        }
        $list['type_status4'] = $type_status4;


        $type_status5 = Db::name('auction')->where('type_status', '=', '5')->where('status', '=', $status)->whereEx($whereCom)->orderRaw('end_time asc,id desc')->limit(1)->select()->getArray();
        if ($type_status5) {
            foreach ($type_status5 as &$val) {
                $temp = $this->get_field_arr($val, ['id', 'type_status', 'goods_id']);
                $val = $temp;
                $val['goods'] = $this->GetGoodsShortDataById4($val['goods_id']);
            }
        }
        $list['type_status5'] = $type_status5;

        return $this->success($status, $list);
    }

    /**
     * 获取拍卖列表
     *
     * @param integer $page 页1
     * @param integer $limit 数量10
     * @param string $search 搜索
     * @param string $type_status 拍卖类型:1=贝壳竞拍,2=降价拍,3=升价拍,4=暗拍(降价拍),5=暗拍(升价拍)
     * @param int $goodscate_id 商品分类:1=精选,2=上新,3=推荐
     * @param string $status 状态:2=预展示,3=进行中
     * @return void
     * @Action
     */
    public function get_auction_list(?int $page = 1, ?int $limit = 10, $apply_status = null, $search = null, $type = null, $status = null, $type_status = null, ?int $goodscate_id = null)
    {

        $page = $page ?: 1;
        $limit = $limit ?: 10;

        $where['apply_status'] = '2';
        $orderRaw = 'end_time asc';

        if ($goodscate_id) {
            if ($goodscate_id < 4) {
                switch ($goodscate_id) {
                    case '1':
                        $orderRaw = 'end_time asc';
                        break;
                    case '2':
                        $orderRaw = 'id asc';
                        break;
                    case '2':
                        $orderRaw = 'end_time asc';
                        break;
                    default:
                        $orderRaw = 'end_time asc';
                        break;
                }
            } else {
                $where['goodscate_id'] = $goodscate_id;
            }
        }




        if ($search)
            $where['title'] = ['like', '%' . $search . '%'];

        $status = $status ?: '2';
        $where['status'] = $status;
        if ($type_status)
            $where['type_status'] = $type_status;

        $list = Db::name('auction')

            // ->whereEx($this->whereCom)

            ->whereEx($where)
            ->whereIsNull('deletetime')
            ->orderRaw($orderRaw)
            ->page($page, $limit)
            ->select()
            ->getArray();
        if ($list) {
            foreach ($list as $key => &$val) {
                $val = $this->ChangeFieldList($val);
            }
        }
        return $this->success('', $list);
    }


    /**
     * 保价买
     * @param int $auction_id 拍卖id
     * @return void
     * @Action
     */
    public function surety_buy($auction_id)
    {
        $auction = $this->getAuctionData($auction_id);
        if($auction['surety_buy']!='yes'){
            return $this->error('不支持保价买');
        }

        //创建保价买订单

    }




    /**
     * 往期列表
     *
     * @param int $id 拍卖id
     * @return void
     * @Action
     */
    public function get_auction_history($id)
    {

        $where['old_id'] = $id;
        $where['or'] = ['id' => $id];
        // $where['status'] = '5';//状态:1=待展示,2=预展示,3=进行中,5=完成结束,6=已下架,7=流拍
        $list = Db::name('auction')
            ->whereEx($where)
            ->orderRaw('id desc')
            // ->where('status','=','5')//状态:1=待展示,2=预展示,3=进行中,5=完成结束,6=已下架,7=流拍
            ->select()->getArray();
        // $auction = $this->getAuctionData($id);
        // if (!$auction) {
        //     return $this->error('没有该活动', $id, CODE_拍卖活动不存在);
        // }

        // $this->AddViewlog(6, $id, $this->auth->user()->id);
        // Db::name('auction')->where('id', '=', $id)->setFieldInc('views', 1)->update();

        // switch ($auction['type_status']) {
        //     case '1':
        //         $拍卖类型 = '贝壳竞拍';
        //         if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_贝壳竞拍)) {
        //             return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
        //         }
        //         break;
        //     case '2':
        //         $拍卖类型 = '降价拍';
        //         if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_降价拍)) {
        //             return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
        //         }
        //         break;
        //     case '3':
        //         $拍卖类型 = '升价拍';
        //         if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_升价拍)) {
        //             return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
        //         }
        //         break;
        //     case '4':
        //         $拍卖类型 = '暗拍(降价拍)';
        //         if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_降)) {
        //             return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
        //         }
        //         break;
        //     case '5':
        //         $拍卖类型 = '暗拍(升价拍)';
        //         if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_升)) {
        //             return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
        //         }
        //         break;
        //     default:
        //         # code...
        //         break;
        // }
        foreach ($list as $key => &$auction) {
            $auction = $this->ChangeFieldHistoryList($auction);
        }


        return $this->success('ok', $list);
    }



    /**
     * 获取拍卖带出价列表
     *
     * @param int $auction_id 拍卖id
     * @param integer $page 1
     * @param integer $limit 10
     * @Action
     * @return void
     */
    public function get_auction_data2($auction_id, ?int $page, ?int $limit)
    {
        $page = $page ?: 1;
        $limit = $limit ?: 10;
        $where['auction_id'] = $auction_id;

        $auction = $this->getAuctionData($auction_id);

        if (!$auction) {
            return $this->error('没有该活动', $id, CODE_拍卖活动不存在);
        }

        $first = Db::name('auction_offer')->whereEx($where)->orderRaw('id desc')->find();
        if ($first) {
            $first['user'] = $this->GetUserData1($first['user_id']);
            $first['date'] = date('m.d H:i:s', $first['time']);
        }

        $count = Db::name('auction_offer')->whereEx($where)->count();
        $list = Db::name('auction_offer')->whereEx($where)->orderRaw('id desc')->page($page, $limit)->select()->getArray();
        foreach ($list as $key => &$val) {
            $val['enroll'] = Db::name('auction_enroll')->where('auction_id', '=', $auction_id)->where('user_id', '=', $val['user_id'])->find();
            $val['user'] = $this->GetUserData1($val['user_id']);
            $val['date'] = date('m.d H:i:s', $val['time']);
        }

        return $this->success('出价列表', ['list' => $list, 'count' => $count ? $count : 0, 'first' => $first, 'auction' => $auction]);
    }





    /**
     * 详情页
     *
     * @param int $id 拍卖id
     * @return void
     * @Action
     */
    public function get_auction_data($id)
    {
        $auction = $this->getAuctionData($id);
        if (!$auction) {
            return $this->error('没有该活动', $id, CODE_拍卖活动不存在);
        }

        $this->AddViewlog(6, $id, $this->auth->user()->id);
        Db::name('auction')->where('id', '=', $id)->setFieldInc('views', 1)->update();

        switch ($auction['type_status']) {
            case '1':
                $拍卖类型 = '贝壳竞拍';
                if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_贝壳竞拍)) {
                    return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
                }
                break;
            case '2':
                $拍卖类型 = '降价拍';
                if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_降价拍)) {
                    return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
                }
                break;
            case '3':
                $拍卖类型 = '升价拍';
                if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_升价拍)) {
                    return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
                }
                break;
            case '4':
                $拍卖类型 = '暗拍(降价拍)';
                if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_降)) {
                    return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
                }
                break;
            case '5':
                $拍卖类型 = '暗拍(升价拍)';
                if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_升)) {
                    return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
                }
                break;
            default:
                # code...
                break;
        }

        $auction = $this->ChangeFieldData($auction);
        return $this->success('ok', $auction);
    }






    // /**
    //  * 报名
    //  *
    //  * @param int $id 拍卖id
    //  * @return void
    //  * @Action
    //  */
    // public function enroll($id)
    // {
    //     $auction = $this->getAuctionData($id);
    //     if (!$auction) {
    //         return $this->error('没有该拍卖', '', CODE_拍卖活动不存在);
    //     }

    //     switch ($auction['type_status']) {
    //         case '1':
    //             $拍卖类型 = '贝壳竞拍';
    //             if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_贝壳竞拍)) {
    //                 return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //             }
    //             break;
    //         case '2':
    //             $拍卖类型 = '降价拍';
    //             if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_降价拍)) {
    //                 return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //             }
    //             break;
    //         case '3':
    //             $拍卖类型 = '升价拍';
    //             if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_升价拍)) {
    //                 return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //             }
    //             break;
    //         case '4':
    //             $拍卖类型 = '暗拍(降价拍)';
    //             if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_降)) {
    //                 return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //             }
    //             break;
    //         case '5':
    //             $拍卖类型 = '暗拍(升价拍)';
    //             if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_暗拍_升)) {
    //                 return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //             }
    //             break;
    //         default:
    //             # code...
    //             break;
    //     }



    //     if ($auction['apply_status'] != '2') {
    //         return $this->error('该拍卖未通过', '', CODE_该拍卖未通过);
    //     }

    //     if ($auction['status'] == '1') {
    //         return $this->error('还未展示', '', CODE_该拍卖不能报名);
    //     }

    //     if ($auction['status'] == '3') {
    //         return $this->error('已经开拍', '', CODE_该拍卖不能报名);
    //     }

    //     //status` enum('1','2','3','5','6') DEFAULT '1' COMMENT '状态:1=待展示,2=预展示,3=进行中,5=结束,6=已下架',
    //     if ($auction['status'] == '2') {

    //         //第一次报名用户减少库存
    //         $data2['auction_id'] = $id;
    //         $_报名_ = Db::name('auction_enroll')->whereEx($data2)->find();
    //         if (!$_报名_) {
    //             $goods_sku_price_arr = explode(',', $auction['goods_sku_price_ids']);
    //             foreach ($goods_sku_price_arr as $key => $sku_id) {
    //                 $this->DecGoodsStock($sku_id, 1, '报名' . $拍卖类型 . '活动减少库存', $id);
    //             }
    //         }

    //         //判断有没有报名过
    //         $data['user_id'] = $this->auth->user()->id;
    //         $data['auction_id'] = $id;
    //         $res = Db::name('auction_enroll')->whereEx($data)->find();
    //         if ($res) {
    //             return $this->error('您已报名该拍卖活动了', '', CODE_您已报名该拍卖活动);
    //         }




    //         //扣除积分
    //         if ($this->auth->score() < $auction['enroll_score']) {
    //             return $this->error('报名积分不足', $auction['enroll_score'], CODE_积分不足);
    //         }
    //         $this->DecUserScore($this->auth->user()->id, (float)$auction['enroll_score'], '报名' . $拍卖类型, 20, $id);
    //         //加入报名


    //         $data['time'] = time();
    //         $data['score'] = $auction['enroll_score'];
    //         $data['return_status'] = '1'; //状态:1=未退积分,2=已退
    //         Db::name('auction_enroll')->insert($data);
    //         $_报名状态缓存_ = 'auction_enroll_' . (string)$id . '_user_id' . (string)$user_id;
    //         Cache::set('redis', $_报名状态缓存_, true);

    //         //判断开始人数
    //         if ($auction['start_status'] == 'number') {
    //             //获取报名总人数
    //             $count = Db::name('auction_enroll')->where('auction_id', '=', $id)->count();
    //             if ($count >= $auction['enroll_num']) {
    //                 //开始拍卖活动
    //                 var_dump('升价拍-人数-报名已满', $count);
    //                 //修改状态              //状态:1=待展示,2=预展示,3=进行中,5=完成结束,6=已下架,7=流拍
    //                 Db::name('auction')->where('id', '=', $id)->update(['updatetime' => time(), 'status' => '3', 'end_time' => time() + $auction['end_s'], 'start_time' => time()]);

    //                 $queue = \Imi\Queue\Facade\Queue::getQueue('auction');
    //                 $message = new \Imi\Queue\Model\Message;
    //                 //发布对列
    //                 $message->setMessage(json_encode(['type' => 'auction_finish3', 'auction' => $auction], JSON_UNESCAPED_UNICODE));
    //                 $queue->push($message, (float)$auction['end_s']);
    //             }
    //         }

    //         return $this->success('报名成功');
    //     } else {
    //         return $this->error('该拍卖不能报名', '', CODE_该拍卖不能报名);
    //     }
    // }

    // /**
    //  * 升价拍出价
    //  *
    //  * @param int $id 拍卖id
    //  * @param int $plus_price 倍数
    //  * @param int $goods_sku_price_id 商品规格
    //  * @param float $price 出价格
    //  * @Action
    //  * @return void
    //  */
    // public function offer3(?int $id, ?int $goods_sku_price_id = null, ?float $plus_price, ?float $price)
    // {



    //     $_当前拍卖缓存_ = 'auction_' . (string)$id;
    //     $auction = Cache::get('redis', $_当前拍卖缓存_);
    //     if (!$auction) {
    //         $auction = $this->getAuctionData($id);
    //         if (!$auction) {
    //             return $this->error('没有该活动', $id, CODE_拍卖活动不存在);
    //         }
    //         Cache::set('redis', $_当前拍卖缓存_, $auction, 1);
    //     }




    //     switch ($auction['type_status']) {
    //         case '1':
    //             $拍卖类型 = '贝壳竞拍';
    //             break;
    //         case '2':
    //             $拍卖类型 = '降价拍';
    //             break;
    //         case '3':
    //             $拍卖类型 = '升价拍';
    //             break;
    //         case '4':
    //             $拍卖类型 = '暗拍(降价拍)';
    //             break;
    //         case '5':
    //             $拍卖类型 = '暗拍(升价拍)';
    //             break;
    //         default:
    //             # code...
    //             break;
    //     }
    //     if (!$this->GetUserSetmod($this->auth->user()->id, $this->auth->user()->set_id, MOD_升价拍)) {
    //         return $this->error('该等级还不支持' . $拍卖类型, $this->auth->user()->set_id);
    //     }

    //     $price = $plus_price * $auction['plus_price'] + $auction['start_price'];

    //     //限高价判断
    //     if ($auction['max_price'] > 0 && $price > $auction['max_price']) {
    //         return $this->error('超过限高价', $auction['max_price'], CODE_超过限高价);
    //     }

    //     //判断活动开始没有
    //     if ($auction['status'] != '3') {
    //         return $this->error('非进行中', '', CODE_该拍卖非进行中);
    //     }

    //     if ($auction['end_time'] < time()) {
    //         return $this->error('活动结束', '', CODE_该拍卖活动结束);
    //     }



    //     $user_id = $this->auth->user()->id;

    //     //判断报名
    //     $_报名状态缓存_ = 'auction_enroll_' . (string)$id . '_user_id' . (string)$user_id;
    //     $_报名状态_ = Cache::get('redis', $_报名状态缓存_);
    //     if (!$_报名状态_) {
    //         $_报名状态存在_ = Cache::has('redis', $_报名状态缓存_);
    //         if (!$_报名状态存在_) {
    //             $data['user_id'] = $user_id;
    //             $data['auction_id'] = $id;
    //             $_报名状态res_ = Db::name('auction_enroll')->whereEx($data)->find();
    //             if ($_报名状态res_) {
    //                 Cache::set('redis', $_报名状态缓存_, true);
    //                 $_报名状态_ = true;
    //             } else {
    //                 Cache::set('redis', $_报名状态缓存_, false);
    //                 $_报名状态_ = false;
    //             }
    //         }
    //     }








    //     $_第一名缓存_ = 'auction_first_user_id' . (string)$id;
    //     $_当前价格缓存_ = 'auction_price_' . (string)$id;


    //     if (!Cache::has('redis', $_第一名缓存_)) {
    //         //第一次报名用户减少库存
    //         $data2['auction_id'] = $id;
    //         $_报名_ = Db::name('auction_enroll')->whereEx($data2)->find();
    //         if (!$_报名_) {
    //             $goods_sku_price_arr = explode(',', $auction['goods_sku_price_ids']);
    //             foreach ($goods_sku_price_arr as $key => $sku_id) {
    //                 $this->DecGoodsStock($sku_id, 1, '出价' . $拍卖类型 . '活动减少库存', $id);
    //             }
    //         }
    //     }


    //     //判断用户出价的价格是否最高
    //     //缓存读当前价格判断  如果最高修改缓存 加入数据库  否则直接返回出价失败
    //     if (Cache::has('redis', $_当前价格缓存_)) {
    //         $_当前价格_ = Cache::get('redis', $_当前价格缓存_);
    //     } else {
    //         $_当前价格_ = (float)$auction['start_price'];
    //     }


    //     if ($_当前价格_ >= $price) {
    //         return $this->error('不能低于当前拍卖价', $_当前价格_, CODE_低于当前拍卖价);
    //     }



    //     switch ($auction['type_status']) {
    //         case '1':
    //             $拍卖类型 = '贝壳竞拍';
    //             break;
    //         case '2':
    //             $拍卖类型 = '降价拍';
    //             break;
    //         case '3':
    //             $拍卖类型 = '升价拍';
    //             break;
    //         case '4':
    //             $拍卖类型 = '暗拍(降价拍)';
    //             break;
    //         case '5':
    //             $拍卖类型 = '暗拍(升价拍)';
    //             break;
    //         default:
    //             # code...
    //             break;
    //     }


    //     //判断用户保证金 够修改价格  扣除保证金 加入报名

    //     if ($this->auth->surety() < $auction['buyer_surety']) {
    //         return $this->error('保证金不足', '', CODE_保证金不足);
    //     }



    //     Cache::set('redis', $_当前价格缓存_, $price);   //设置当前最高价格
    //     Cache::set('redis', $_第一名缓存_, $user_id);   //设置第一名用户

    //     $_第一名用户id_ = Cache::get('redis', $_第一名缓存_);
    //     if ($_第一名用户id_) {
    //         if ($_第一名用户id_ != $user_id) {
    //             //修改领先人
    //             $this->UpdateFirst($id, $user_id);
    //         }
    //     }











    //     //插入出价
    //     $data['user_id'] = $user_id;
    //     $data['auction_id'] = $id;
    //     $data['price'] = $price;
    //     $data['goods_sku_price_id'] = $goods_sku_price_id;
    //     $data['time'] = $this->time();
    //     $data['type_status'] = $auction['type_status'];
    //     $data['enroll_status'] = $_报名状态_ ? '2' : '1';
    //     $data['status'] = '1';
    //     $data['id'] =  Db::name('auction_offer')->insert($data)->getLastInsertId();
    //     $this->DecUserSurety($user_id, $auction['buyer_surety'], $拍卖类型 . $id . '出价', $拍卖类型, $data['id']);

    //     //加入对列 修改在此时间之后且 此id以后的全出局,解冻保证金

    //     $queue = \Imi\Queue\Facade\Queue::getQueue('auction');
    //     $message = new \Imi\Queue\Model\Message;
    //     //发布对列
    //     $message->setMessage(json_encode(['type' => 'auction_out', 'data' => ['id' => $data['id']], 'auction' => $auction], JSON_UNESCAPED_UNICODE));
    //     $queue->push($message);
    //     Db::name('auction')->where('id', '=', $auction['id'])->update(['now_price' => $price]);

    //     //判断限高价 如果达到限高价就结束
    //     if ($auction['max_price'] > 0) {
    //         if (($price + $auction['plus_price']) >= $auction['max_price']) {
    //             //活动结束
    //             $queue2 = \Imi\Queue\Facade\Queue::getQueue('auction');
    //             $message2 = new \Imi\Queue\Model\Message;
    //             //发布对列
    //             $message2->setMessage(json_encode(['type' => 'auction_finish' . $auction['type_status'], 'auction' => $auction], JSON_UNESCAPED_UNICODE));
    //             $queue2->push($message2);
    //         }
    //     }

    //     // Cache::set('redis', 'auction_first_user_id' . (string)$id, 'value');
    //     //判断是否已经出价
    //     // Db::name('auction_offer')->where('id','=',$id)->order('ti');
    //     return $this->success('出价成功');
    // }

    public function 获取用户拍卖已报名ID数组($user_id)
    {

        return Db::name('auction_enroll')->where('user_id', '=', $user_id)->column('auction_id');
    }

    public function 获取用户拍卖已报名或出过价ID数组($user_id)
    {
        $arr1 = $this->获取用户拍卖已报名ID数组($user_id);
        $arr2 = Db::name('auction_offer')->where('user_id', '=', $user_id)->column('auction_id');
        $arr = array_merge($arr1, $arr2);
        if ($arr)
            $arr = array_unique($arr);
        return $arr;
    }


    // AuctionOrderBean





    /**
     * 获取我的列表
     *
     * @param integer $page 页1
     * @param integer $limit 数量10
     * @param string $type wait_start=待开拍,ing=进行中,over=结束,success=已拍下
     * @param string $type_status 拍卖类型:1=贝壳竞拍,2=降价拍,3=升价拍,4=暗拍(降价拍),5=暗拍(升价拍)
     * @return void
     * @Action
     */
    public function get_my_list(?string $type = null, ?int $page = 1, ?int $limit = 10,  $search = null,  $status = null, $type_status = null)
    {
        //     * @param string $status 状态:un=待操作,post=寄拍,buy=购买,timeout=超时(针对于拍中的)
        $page = $page ?: 1;
        $limit = $limit ?: 10;

        $where['user_id'] = $user_id =  $this->auth->user()->id;
        $orderRaw = 'end_time asc';

        $where_com1 = [];
        $where_com2 = [];

        if ($type_status)
            $where_com1['type_status'] = $type_status;


        switch ($type) {
            case 'wait_start':
                $获取用户拍卖已报名ID数组 = $this->获取用户拍卖已报名ID数组($user_id);
                $where_com1['id'] = ['in', $获取用户拍卖已报名ID数组];
                $where_com1['status'] = ['=', '2'];

                break;
            case 'ing':
                $获取用户拍卖已报名或出过价ID数组 = $this->获取用户拍卖已报名或出过价ID数组($user_id);
                $where_com1['id'] = ['in', $获取用户拍卖已报名或出过价ID数组];
                $where_com1['status'] = ['=', '3'];

                break;
            case 'over':
                $获取用户拍卖已报名或出过价ID数组 = $this->获取用户拍卖已报名或出过价ID数组($user_id);
                $where_com1['id'] = ['in', $获取用户拍卖已报名或出过价ID数组];
                $where_com1['status'] = ['>=', '5'];

                break;
            case 'success':
                $where_com1['user_id'] = ['=', $user_id];
                $where_com1['status'] = ['=', '5'];
                break;

            default:

                $获取用户拍卖已报名或出过价ID数组 = $this->获取用户拍卖已报名或出过价ID数组($user_id);
                $where_com1['id'] = ['in', $获取用户拍卖已报名或出过价ID数组];
                break;
        }

        if (!$where_com1) {
            return $this->success('无');
        }

        var_dump($where_com1);

        $list = Db::name('auction')

            // ->whereEx($this->whereCom)

            ->whereEx($where_com1)
            // ->whereIsNull('deletetime')
            ->orderRaw($orderRaw)
            ->page($page, $limit)
            ->select()
            ->getArray();
        if ($list) {
            foreach ($list as $key => &$val) {
                $val = $this->ChangeMyFieldList($val, $user_id);
            }
        }

        return $this->success('', $list);
    }




    /**
     * 改变我的字段
     *
     * @param array $val 
     * @return void
     */
    protected function ChangeMyFieldList(&$val, $user_id)
    {
        $自己拍中 = false;
        $val['self_success'] = $自己拍中;

        $保价买 = false;
        $val['baojiamai'] = $保价买;

        //status	status	47		状态:1=待展示,2=预展示,3=进行中,5=完成结束,6=已下架,7=流拍
        switch ($val['status']) {
            case '2':
                $val['auction_enroll'] = Db::name('auction_enroll')->where('user_id', '=', $user_id)->find();
                break;

            case '3':

                $val['auction_enroll'] = Db::name('auction_enroll')->where('user_id', '=', $user_id)->find();
                $val['auction_offer'] = Db::name('auction_offer')->where('user_id', '=', $user_id)->orderRaw('id desc')->find();
                break;

            case '6':
                $val['auction_enroll'] = Db::name('auction_enroll')->where('user_id', '=', $user_id)->find();
                $val['auction_offer'] = Db::name('auction_offer')->where('user_id', '=', $user_id)->orderRaw('id desc')->find();

                break;

            case '5':

                $val['auction_enroll'] = Db::name('auction_enroll')->where('user_id', '=', $user_id)->find();
                $val['auction_offer'] = Db::name('auction_offer')->where('user_id', '=', $user_id)->orderRaw('id desc')->find();

                if ($val['user_id'] == $user_id) {
                    $自己拍中 = true;
                    $val['auction_success'] = Db::name('auction_success')->where('user_id', '=', $user_id)->where('auction_id','=',$val['id'])->find();
                } else {
                    $保价买 = true;
                }

                break;

            default:
                $val['auction_enroll'] = Db::name('auction_enroll')->where('user_id', '=', $user_id)->find();
                $val['auction_offer'] = Db::name('auction_offer')->where('user_id', '=', $user_id)->orderRaw('id desc')->find();

                $保价买 = true;



                break;
        }

        switch ($val['type_status']) {
            case '1':
                $拍卖类型 = '贝壳竞拍';
                $val['auction_offer_count_shell'] = Db::name('auction_offer')->where('user_id', '=', $user_id)->sum('shell');
                break;
            case '2':
                $拍卖类型 = '降价拍';
                break;
            case '3':
                $拍卖类型 = '升价拍';
                break;
            case '4':
                $拍卖类型 = '暗拍(降价拍)';

                break;
            case '5':
                $拍卖类型 = '暗拍(升价拍)';

                break;
            default:
                
                break;
        }



        if ($val['start_status'] == 'number') {
            $number_num = Db::name('auction_enroll')->where('auction_id', '=', $val['id'])->count();
            $val['number_num'] = $number_num ?? 0;
        }


        $val['date_str'] = $this->TimeToStr($val['createtime']);
        if ($val['start_time'] > 0) {
            $val['start_date'] = date('Y-m-d H:i:s', $val['start_time']);

            if ($val['start_time'] > time())
                $val['have_start_s'] = $val['start_time'] - time();
        }

        if ($val['end_time'] > 0) {
            $val['end_date'] = date('Y-m-d H:i:s', $val['end_time']);

            if ($val['end_time'] > time())
                $val['have_end_s'] = $val['end_time'] - time();
        }



        $val['date'] = date('Y-m-d H:i:s', $val['createtime']);
        if ($val['store_id'] > 0)
            $val['store'] = $this->getStoreData2($val['store_id']);
        $val['goods'] = $this->GetGoodsShortDataById2($val['goods_id']);

        if(sizeof(explode(',', $val['goods_sku_price_ids']))==1){
            // $goods_sku_price = Db::name('goods')->where('id','=',$val['goods_sku_price_ids'])->fieldRaw()->find();
            // $goods = Db::name('goods')->where('id','=',$goods_sku_price_ids['goods_id'])->find();
            // $goods_sku_price['image'] = $goods['image'];
            // $goods_sku_price['goods_sku_text'] = '';
            $goods_sku_price = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
            $goods_sku_price[0]['image'] = $val['goods']['image'];
            $goods_sku_price[0]['goods_sku_text'] = '默认';
            $val['goodssku_price_list'] = $goods_sku_price;
        }else{
            $val['goodssku_price_list'] = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
        
        }
        

        if ($val['minimum_price'] > 0) {
            $val['minimum_price'] = '有';
        } else {
            $val['minimum_price'] = '无';
        }

        if ($val['surety_buy'] == 'yes' && $保价买 && ($val['end_time'] + 3600) > time()) {
            $val['baojiamai'] = $保价买;
            $val['baojiamai_date'] = date('Y-m-d H:i:s', $val['end_time'] + 3600);
        }

        if ($自己拍中){
            var_dump($val);
            if($val['auction_success'])
            $val['auction_success']['end_date'] = date('Y-m-d H:i:s', $val['auction_success']['end_time']);
        }
            

        $val['self_success'] = $自己拍中;
        // unset($val['minimum_price']); //卸载保留价
        return $val;
    }



    /**
     * 改变字段
     *
     * @param array $val 
     * @return void
     */
    protected function ChangeSuccessFieldList(&$val)
    {
        $auction = $this->getAuctionData($val['auction_id']);
        $val['auction'] = $auction;
        return $val;
    }




    /**
     * 获取毫秒时间戳
     *
     * @return int
     */
    private function time()
    {
        return microtime(true) * 10000;
    }




    /**
     * 更新第一
     *
     * @param int $id
     * @param int $user_id
     * @return void
     */
    private function UpdateFirst($id, $user_id)
    {
        Db::name('auction')->where('id', '=', $id)->update(['user_id' => $user_id]);
    }


    /**
     * 改变字段
     *
     * @param array $val 
     * @return void
     */
    protected function getAuctionData($id)
    {
        $auction = Db::name('auction')->where('id', '=', $id)->find();
        return $auction;
    }





    /**
     * 改变字段
     *
     * @param array $val 
     * @return void
     */
    protected function ChangeFieldList(&$val)
    {

        switch ($val['type_status']) {
            case '1':
                $拍卖类型 = '贝壳竞拍';
                break;
            case '2':
                $拍卖类型 = '降价拍';



                break;
            case '3':
                $拍卖类型 = '升价拍';


                $_当前价格缓存_ = 'auction_price_' . (string)$val['id'];
                if (Cache::has('redis', $_当前价格缓存_)) {
                    $_当前价格_ = Cache::get('redis', $_当前价格缓存_);
                } else {
                    $_当前价格_ = (float)$val['start_price'];
                }
                $val['now_price'] = $_当前价格_;

                break;
            case '4':
                $拍卖类型 = '暗拍(降价拍)';
                break;
            case '5':
                $拍卖类型 = '暗拍(升价拍)';


                break;
            default:
                # code...
                break;
        }


        if ($val['status'] == 3 && $val['end_time'] > 0 && $val['end_time'] < time()) {
            // if ($val['start_status'] == 'time') {
            //结束了
            $queue2 = \Imi\Queue\Facade\Queue::getQueue('auction');
            $message2 = new \Imi\Queue\Model\Message;
            //发布对列
            $message2->setMessage(json_encode(['type' => 'auction_finish' . $val['type_status'], 'auction' => $val], JSON_UNESCAPED_UNICODE));
            $queue2->push($message2);
            // }
        }



        if ($val['start_status'] == 'number') {
            $number_num = Db::name('auction_enroll')->where('auction_id', '=', $val['id'])->count();
            $val['number_num'] = $number_num ?? 0;
        }


        $val['date_str'] = $this->TimeToStr($val['createtime']);
        if ($val['start_time'] > 0) {
            $val['start_date'] = date('Y-m-d H:i:s', $val['start_time']);

            if ($val['start_time'] > time())
                $val['have_start_s'] = $val['start_time'] - time();
        }

        if ($val['end_time'] > 0) {
            $val['end_date'] = date('Y-m-d H:i:s', $val['end_time']);

            if ($val['end_time'] > time())
                $val['have_end_s'] = $val['end_time'] - time();
        }



        $val['date'] = date('Y-m-d H:i:s', $val['createtime']);
        if ($val['store_id'] > 0)
            $val['store'] = $this->getStoreData2($val['store_id']);
        $val['goods'] = $this->GetGoodsShortDataById2($val['goods_id']);


        if(sizeof(explode(',', $val['goods_sku_price_ids']))==1){
            // $goods_sku_price = Db::name('goods')->where('id','=',$val['goods_sku_price_ids'])->fieldRaw()->find();
            // $goods = Db::name('goods')->where('id','=',$goods_sku_price_ids['goods_id'])->find();
            // $goods_sku_price['image'] = $goods['image'];
            // $goods_sku_price['goods_sku_text'] = '';
            $goods_sku_price = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
            $goods_sku_price[0]['image'] = $val['goods']['image'];
            $goods_sku_price[0]['goods_sku_text'] = '默认';
            $val['goodssku_price_list'] = $goods_sku_price;
            var_dump('234234sfsdsfsd');
        }else{
            var_dump('1231231');
            $val['goodssku_price_list'] = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
        
        }
        // $val['goodssku_price_list'] = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();

        if ($val['minimum_price'] > 0) {
            $val['minimum_price'] = '有';
        } else {
            $val['minimum_price'] = '无';
        }
        // unset($val['minimum_price']); //卸载保留价
        return $val;
    }


    /**
     * 详情页改变字段
     *
     * @param array $val 
     * @return void
     */
    protected function ChangeFieldData($val)
    {

        switch ($val['type_status']) {
            case '1':
                $拍卖类型 = '贝壳竞拍';
                break;
            case '2':
                $拍卖类型 = '降价拍';
                break;
            case '3':
                $拍卖类型 = '升价拍';

                if ($val['end_time'] < time()) {
                    if ($val['start_status'] == 'time') {
                        //结束了
                        $queue2 = \Imi\Queue\Facade\Queue::getQueue('auction');
                        $message2 = new \Imi\Queue\Model\Message;
                        //发布对列
                        $message2->setMessage(json_encode(['type' => 'auction_finish' . $val['type_status'], 'auction' => $val], JSON_UNESCAPED_UNICODE));
                        $queue2->push($message2);
                    }
                }
                $_当前价格缓存_ = 'auction_price_' . (string)$val['id'];
                if (Cache::has('redis', $_当前价格缓存_)) {
                    $_当前价格_ = Cache::get('redis', $_当前价格缓存_);
                } else {
                    $_当前价格_ = (float)$val['start_price'];
                }
                $val['now_price'] = $_当前价格_;
                break;
            case '4':
                $拍卖类型 = '暗拍(降价拍)';
                break;
            case '5':
                $拍卖类型 = '暗拍(升价拍)';
                break;
            default:
                # code...
                break;
        }

        if ($val['start_status'] == 'number') {
            $number_num = Db::name('auction_enroll')->where('auction_id', '=', $val['id'])->count();
            $val['number_num'] = $number_num ?? 0;
        }


        $val['date_str'] = $this->TimeToStr($val['createtime']);
        if ($val['start_time'] > 0) {
            $val['start_date'] = date('Y-m-d H:i:s', $val['start_time']);

            if ($val['start_time'] > time())
                $val['have_start_s'] = $val['start_time'] - time();
        }

        if ($val['end_time'] > 0) {
            $val['end_date'] = date('Y-m-d H:i:s', $val['end_time']);

            if ($val['end_time'] > time())
                $val['have_end_s'] = $val['end_time'] - time();
        }


        $val['self_enroll'] = Db::name('auction_enroll')->where('auction_id', '=', $val['id'])->where('user_id', '=', $this->auth->user()->id)->count();
        $val['auction_offer'] = Db::name('auction_offer')->where('auction_id', '=', $val['id'])->where('user_id', '=', $this->auth->user()->id)->find();


        $val['date'] = date('Y-m-d H:i:s', $val['createtime']);
        if ($val['store_id'] > 0)
            $val['store'] = $this->getStoreData3($val['store_id']);
        $val['goods'] = $this->GetGoodsShortDataByIdAuction($val['goods_id']);


        if(sizeof(explode(',', $val['goods_sku_price_ids']))==1){
            // $goods_sku_price = Db::name('goods')->where('id','=',$val['goods_sku_price_ids'])->fieldRaw()->find();
            // $goods = Db::name('goods')->where('id','=',$goods_sku_price_ids['goods_id'])->find();
            // $goods_sku_price['image'] = $goods['image'];
            // $goods_sku_price['goods_sku_text'] = '';
            $goods_sku_price = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
            $goods_sku_price[0]['image'] = $val['goods']['image'];
            $goods_sku_price[0]['goods_sku_text'] = '默认';
            $val['goodssku_price_list'] = $goods_sku_price;
        }else{
            $val['goodssku_price_list'] = GoodsskuPrice::dbQuery()->whereIn('id', explode(',', $val['goods_sku_price_ids']))->fieldRaw('id,goods_sku_ids,image,price,goods_sku_text,stock')->select()->getArray();
        
        }
       
        // unset($val['minimum_price']); //卸载保留价
        if ($val['minimum_price'] > 0) {
            $val['minimum_price'] = '有';
        } else {
            $val['minimum_price'] = '无';
        }

        $val['rule_id'] = (int)$val['type_status'];
        // $val['after_sales_id'] = 8;
        $val['server_ensure_id'] = 100;
        $val['help_id'] = 99;

        return $val;
    }





    /**
     * 详情页改变字段
     *
     * @param array $val 
     * @return void
     */
    protected function ChangeFieldHistoryList($val)
    {

        switch ($val['type_status']) {
            case '1':
                $拍卖类型 = '贝壳竞拍';
                break;
            case '2':
                $拍卖类型 = '降价拍';
                break;
            case '3':
                $拍卖类型 = '升价拍';
                break;
            case '4':
                $拍卖类型 = '暗拍(降价拍)';
                break;
            case '5':
                $拍卖类型 = '暗拍(升价拍)';
                break;
            default:
                # code...
                break;
        }
        unset($val['minimum_price']); //卸载保留价
        if ($val['user_id'] > 0)
            $val['user'] = $this->GetUserData1($val['user_id']);
        // if ($val['minimum_price'] > 0) {
        //     $val['minimum_price'] = '有';
        // } else {
        //     $val['minimum_price'] = '无';
        // }
        return $val;
    }







    /**
     * 添加收藏拍卖
     *
     * @param int $auction_id 拍卖id
     * @return void
     * @Action
     */
    public function add_likes($auction_id)
    {
        $res = Db::name('auction')->where('id', '=', $auction_id)->count();
        if ($res < 1) {
            return $this->error('没有该拍卖活动');
        }
        $this->AddShoucang(AUCTION, $auction_id, $this->auth->user()->id);

        $this->update_likes($auction_id);
        return $this->success('收藏成功');
    }


    /**
     * 删除收藏拍卖
     *
     * @param int $auction_id 拍卖id
     * @return void
     * @Action
     */
    public function del_likes($auction_id)
    {
        $this->DelShoucang(AUCTION, $auction_id, $this->auth->user()->id);
        $this->update_likes($auction_id);
        return $this->success('取消成功');
    }

    /**
     * 更新收藏
     *
     * @param int $auction_id 
     * @return void
     */
    protected function update_likes($auction_id)
    {
        $data['typestatus_id'] = AUCTION;
        $data['public_id'] = $auction_id;
        $count = Db::name('likes')->whereEx($data)->count();
        Db::name('auction')->where('id', '=', $auction_id)->update(['likes' => $count]);
    }

    /**
     * 获取收藏拍卖列表
     *
     * @param integer $page 1
     * @param integer $limit 50
     * @return void
     * @Action
     */
    public function get_likes_auction_list(?int $page = 1, ?int $limit = 50)
    {
        //查询拍卖id
        $page = $page ?: 1;
        $limit = $limit ?: 50;

        $data['user_id'] = $this->auth->user()->id;
        $data['typestatus_id'] = AUCTION;

        $auction_arr = Db::name('likes')->whereEx($data)->orderRaw('time desc')->column('public_id');
        $list = [];
        if ($auction_arr)
            foreach ($auction_arr as $key => $auction_id) {

                $auction = $this->getAuctionData($auction_id); //拍卖信息

                // $whereGoods['apply_status'] = '2';//通过审核
                // $whereGoods['auction_id'] = $auction_id;
                // $whereGoods['status'] = 'up';
                // $auction['goods_list'] = Db::name('goods')
                // // ->whereEx($this->whereCom)
                // ->whereEx($whereGoods)
                // ->orderRaw('createtime desc')
                // ->whereIsNull('deletetime')
                // ->page(1, 4)
                // ->select()->getArray();

                // if ($lat && $lng)
                //     $auction['km'] = $this->get_coordinate_distance($lng, $lat, $auction['lng'], $auction['lat']);
                $list[] = $auction;
            }

        return $this->success('收藏拍卖', $list);
    }


    /**
     * 获取用户信息头像昵称
     *
     * @param int $id 用户id
     * @return void
     */
    protected function GetUserData1($id)
    {
        return Db::name('user')->where('id', '=', $id)->fieldRaw('nickname,avatar')
            // ->cache($this->db_cache_set)
            ->find();
    }
}
